/*
 * @Description: SyncWaterfallHook 遇到有返回值时, 会把该返回值返回给下一个回调的接收值
 * @Author: wangqi
 * @Date: 2021-04-17 11:59:14
 * @LastEditTime: 2021-04-17 22:19:07
 */

// 同步瀑布函数，可用来接收处理上一次的返回值
let { SyncWaterfallHook } = require('tapable');

class Lesson {
    constructor() {
        this.hook = {
            arch: new SyncWaterfallHook(['name', 'age']),
        }
    }

    tap() {
        this.hook.arch.tap('node', (...res) => {
            console.log("来自外部传入|", ...res)
            let obj = { "state": 'node学的不错' }
            return obj
        });

        this.hook.arch.tap('vue', (...res) => {
            console.log("来自node|", ...res)
            let obj = { "state": 'vue也不错' }
            return obj
        });
        this.hook.arch.tap('react', (...res) => {
            console.log("来自vue|", ...res)
            let obj = { "state": 'react也不错' }
            return obj
        });
    }

    start() {
        this.hook.arch.call('wq', '12')
    }
}

let lesson = new Lesson();

lesson.tap();
lesson.start();
